/**
 * User: yangxiul
 * Date: 16-8-18
 * Time: 上午9:04
 * 土地拓展过程管控统计报表
 * 统计的外业拓展对象:[拓展小组]中的人员
 */

define("require dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/fx dojo/fx/easing ../../util/ajaxUtil dojo/dom dojo/dom-attr dojo/dom-class dojo/dom-style dojo/on dojo/query dojo/topic ../BaseWidget esri/symbols/SimpleFillSymbol esri/symbols/PictureMarkerSymbol esri/symbols/SimpleLineSymbol esri/symbols/SimpleMarkerSymbol esri/graphic esri/layers/GraphicsLayer esri/Color esri/SpatialReference esri/geometry/Point gistech/util/infoUtil esri/symbols/PictureMarkerSymbol dojo/text!./templates/Template.html".split(" "),
    function (require, declare, lang, array, fx,easing,ajaxUtil, dom, domAttr, domClass, domStyle, on, query, topic, BaseWidget,SimpleFillSymbol,PictureMarkerSymbol,SimpleLineSymbol,SimpleMarkerSymbol,Graphic,GraphicsLayer,Color,SpatialReference,Point,infoUtil,PictureMarkerSymbol,template) {

        return declare([BaseWidget], {
            templateString: template,
            map: null,
            rightTab:null,
            ismove:false,//组件位置移动判断
            grouplist:null,
            projectlist:null,
            departmentType:"company",
            projectType:"mocha",
            projectTypeWords:"核查项目",
            orgFields:null,
            
            reportstarttime:null,
            reportendtime:null,
            
            currentDataList:null,
            
            OrganizationList:null,
            
            companyList:null,
            departmentList:null,
            teamGroupList:null,
            
            datatableheader:null,
            landareaGraphicLayer:null,
            texporttabletitleinfo:"",
            POISymbols:[],
            sortinfo:{
            	sortfield:"WCD",
            	desc:"desc",
            	fieldtype:"Number",
            	fieldtext:"完成度"
            },
            constructor: function (args) {
                this.map = args.map;
                this.rightTab = args.rightTab;
            },

            postCreate: function () {
            	  this.inherited(arguments);
    			this.grouplist = dojo.query(".grouplist li");
    			for(var i=0;i<this.grouplist.length;i++){
    				on(this.grouplist[i], "click",lang.hitch(this,this.changeDepartmentTypeHandler));//组织机构切换
    			}
    			
    			this.projectlist = dojo.query(".selProjectTypeList input");
    			for(var i=0;i<this.projectlist.length;i++){
    				on(this.projectlist[i], "click",lang.hitch(this,this.changeProjectTypeHandler)); //项目类型切换
    			}
    			
    			on(this.tongjiBtn, "click",lang.hitch(this,this.tongjiBtnClick));
    			on(this.closebtn,"click",lang.hitch(this,this.closeDialog));
 
    			topic.subscribe("windowResize", lang.hitch(this, this.windowResizeHandler));
    			if(ioc.map.userInfoData.isManager){
    				on(this.exportBtn, "click",lang.hitch(this,this.exportBtnClick));
    			}else{
    				//隐藏导出按钮
    				dojo.byId('landManagerExport').style.display='none';
    				//隐藏导出TD
    				//dojo.byId('exportTd').style.display='none';
    				dojo.toggleClass(dojo.byId('exportTd'),"colshowstate",true);
    				
    			}
    			
 
    			on(this.fieldssort, "click",lang.hitch(this,this.changeSortFieldHandler));
 
            },

            startup: function () {
                this.inherited(arguments);
                this.init();
            },

            init:function(){
            	this.companyList = [];
            	this.departmentList = [];
            	this.teamGroupList = [];
            	this.tableheader = dojo.query(".t1 .dynamic");
                this.datatableheader = dojo.query(".t2 .dynamic");
                //表格的列
                this.orgFields = {
                		"company":"COMPANY#60,COMPANYLEADER#60,GNUM#60,PNUM#100,ZHIBIAO#80,WCD#60",
                		"department":"COMPANY#60,DEPARTMENT#120,DEPARTMENTLEADER#60,GNUM#60,PNUM#100,ZHIBIAO#80,WCD#60",
                		"teamgroup":"COMPANY#60,DEPARTMENT#120,TEAM#100,TEAMLEADER#80,PNUM#100,ZHIBIAO#80,WCD#60"
                };
                this.reportstarttime = dojo.byId("reportstarttime");
                this.reportstarttime.value = reduceformatDate(30,"-");
                
                this.reportendtime = dojo.byId("reportendtime");
                this.reportendtime.value = reduceformatDate(0,"-");
                
            	this.landareaGraphicLayer = new GraphicsLayer(); //创建地块区域面要素展示图层
            	//存储所有graphic图层
				ioc.map.graphiclayers.push(this.landareaGraphicLayer);
    			this.map.addLayer(this.landareaGraphicLayer);
    			on(this.landareaGraphicLayer,"click",lang.hitch(this,function(e){
					topic.publish("graphicClickEvent",e);
				}))
    			if(ioc.map.userOrganization&&ioc.map.userOrganization.length>0){
    				this.getOrganizationList();
    			}
    			else{
    				this.getTaskTarget();
    			}
    			
    			//点符号,用于定位当前选中的缓冲区查询结果列表项位置
        		var hechaPOISymbol = new esri.symbol.PictureMarkerSymbol(require.toUrl("../MapLayerResourceWidget/images/hechaflag.png"),48,48);
        		hechaPOISymbol.setOffset(0, 0);
        		this.POISymbols.push(hechaPOISymbol);
        		var qiatanPOISymbol = new esri.symbol.PictureMarkerSymbol(require.toUrl("../MapLayerResourceWidget/images/qiatanflag.png"),48,48);
        		qiatanPOISymbol.setOffset(0, 0);
        		this.POISymbols.push(qiatanPOISymbol);
        		var huoquPOISymbol = new esri.symbol.PictureMarkerSymbol(require.toUrl("../MapLayerResourceWidget/images/huoquflag.png"),48,48);
        		huoquPOISymbol.setOffset(0, 0);
        		this.POISymbols.push(huoquPOISymbol);
        		this.windowResizeHandler();
            },
            
            windowResizeHandler:function(){
            	//根据浏览器高度设置表格高度，避免双滚动条出现
        		dojo.query(".tabledatarows").style("max-height", document.body.clientHeight-320+"px");
        		dojo.query(".rightWidgetRoot .dijitContentPane").style("width", "100%");
        		dojo.query(".rightWidgetRoot .dijitContentPane").style("height", "100%");
            },
            getTaskTarget:function(){
            	//集团/事业部/拓展组关系
            	ajaxUtil.request("../client/service/landStatisticsController/queryTaskTarget",
            			"",lang.hitch(this,function(result){
       	    			 var Store = eval(result.result);
    	    			 if(Store!=null && Store.length>0){
    	    				
    	    				 ioc.map.userOrganization = Store;
    	    			 }else{
    	    				 ioc.map.userOrganization = [];
    	    			 }
    	    			 this.getOrganizationList();
    	    			 }));
            },
            getOrganizationList:function(){
            	ajaxUtil.request("../client/service/landStatisticsController/queryOrganizationList",
            			"departmentType="+this.departmentType+"&projectType=核查项目&startdate="+this.reportstarttime.value+"&enddate="+this.reportendtime.value,lang.hitch(this,function(result){
            				this.OrganizationList = [];
            				var res = result.rows;
            				//this.currentDataList = dojo.clone(result.rows[0].land);
            				for(var i=0;i<res.length;i++){
            					var company = null;
            					for(var j=0;j<this.OrganizationList.length;j++){
            						if(this.OrganizationList[j].name==res[i].COMPANY){
            							company = this.OrganizationList[j];
            							break;
            						}
            					}
            					//集团,公司
            					if(company==null){
            						company = {
            								name:res[i].COMPANY,orgId:res[i].COMPANYORGID,gnum:1, companyLeader:res[i].COMPANYLEADER,
            								list:[
            								      {name:res[i].DEPARTMENT,orgId:res[i].DEPTORGID,gnum:1, departmentLeader:res[i].DEPARTMENTLEADER,
            								    	  list:[
            								    	        {name:res[i].TEAM,orgId:res[i].DEVELOPORGID,leader:res[i].TEAMLEADER}
            								    	        ]
            								      }
            								      ]
            						};
            						this.OrganizationList.push(company);
            					}else{
            						var departmentlist  = company.list;
            						var department = null;
            						for(var k=0;k<departmentlist.length;k++){
                						if(departmentlist[k].name==res[i].DEPARTMENT){
                							department = departmentlist[k];
                							break;
                						}
                					}
            						if(department == null){
            							department = {name:res[i].DEPARTMENT,orgId:res[i].DEPTORGID,gnum:1,departmentLeader:res[i].DEPARTMENTLEADER,
  								    	              list:[
  								    	                     {name:res[i].TEAM,orgId:res[i].DEVELOPORGID,leader:res[i].TEAMLEADER}
  								    	                   ]
  								                     };
            							company.list.push(department);
            							company.gnum++;
            						}else{
            							var team = {name:res[i].TEAM,orgId:res[i].DEVELOPORGID,leader:res[i].TEAMLEADER};
            							department.list.push(team);
            							department.gnum++;
            							company.gnum++;
            						}
            					}
            					
            					//标记小组内有多少人[用于任务指标]
            					if(ioc.map.userOrganization!=null){
            						var count =0;
            						var hechaCount = 0;
            						var qiatanCount = 0;
            						for(var g=0; g<ioc.map.userOrganization.length;g++ ){
            							var data = ioc.map.userOrganization[g];
//            							if(data.COMPANYNAME==res[i].COMPANY && data.BUSINESSNAME==res[i].DEPARTMENT && data.DEVELOPNAME==res[i].TEAM){
//            								count++;
//            							}
            							if(data.ORG_ID == res[i].DEVELOPORGID){
            								if(data.WYTZ_TYPE == '1'){ //核查指标
            									hechaCount = data.TARGET;
            								}
            								if(data.WYTZ_TYPE == '2'){//洽谈指标
            									qiatanCount = data.TARGET;
            								}
            							}
            							
            						}
            					}
            					res[i]["LANDXHS"] = [];
            					res[i]["PNUM"] = 0;
            					res[i]["ZHIBIAO"] = count;
            					res[i]["HECHACOUNT"] = hechaCount;
            					res[i]["QIATANCOUNT"] = qiatanCount;
            					res[i]["WCD"] =0;
            					this.teamGroupList.push(res[i]);
            				}
            				
            				for(var i=0;i<this.OrganizationList.length;i++){
            					var org = this.OrganizationList[i];
            					//标记集团内有多少人[用于任务指标]
        						var companyUsers = 0;
        						var hechaCompanyCount = 0;
        						var qiatanCompanyCount = 0;
        						for(var g=0; g<ioc.map.userOrganization.length;g++ ){
        							var data = ioc.map.userOrganization[g];
//        							if(data.COMPANYNAME==org.name ){
//        								companyUsers++;
//        							}
        							if(data.ORG_ID == org.orgId){
        								if(data.WYTZ_TYPE == '1'){ //核查指标
        									hechaCompanyCount = data.TARGET;
        								}
        								if(data.WYTZ_TYPE == '2'){//洽谈指标
        									qiatanCompanyCount = data.TARGET;
        								}
        							}
        						}
        						
            					//"company"
            					this.companyList.push(
            							{COMPANY:org.name,COMPANYLEADER:org.companyLeader,
            								GNUM:org.gnum,PNUM:0,ZHIBIAO:companyUsers,WCD:0,
            								LANDXHS:[],HECHACOUNT:hechaCompanyCount,QIATANCOUNT:qiatanCompanyCount}
            							);
            				
            					//"department"
            					for(var j=0;j<org.list.length;j++){
            						var depa = org.list[j];
            						
            						//标记事业部门内有多少人[用于任务指标]
                					var businessUsers = 0;
            						var hechaDeptCount = 0;
            						var qiatanDeptCount = 0;
              						for(var g=0; g<ioc.map.userOrganization.length;g++ ){
            							var data = ioc.map.userOrganization[g];
//            							if(data.COMPANYNAME==org.name && data.BUSINESSNAME==depa.name ){
//            								businessUsers++;
//            							}
            							if(data.ORG_ID == depa.orgId){
            								if(data.WYTZ_TYPE == '1'){ //核查指标
            									hechaDeptCount = data.TARGET;
            								}
            								if(data.WYTZ_TYPE == '2'){//洽谈指标
            									qiatanDeptCount = data.TARGET;
            								}
            							}
            							
            						}
            						this.departmentList.push(
            								{COMPANY:org.name,DEPARTMENT:depa.name,DEPARTMENTLEADER:depa.departmentLeader,GNUM:depa.gnum,
            									PNUM:0,ZHIBIAO:businessUsers,WCD:0,LANDXHS:[],HECHACOUNT:hechaDeptCount,QIATANCOUNT:qiatanDeptCount});
            					}
            				}
            				this.loadData();
            			}),function(){
            		console.error("获取组织机构数据失败");
            	});
            },
            tongjiBtnClick:function(){
             	   if( this.reportstarttime.value.replace(" ","")==""|| this.reportendtime.value.replace(" ","")==""){
              		    alert("统计时段不能为空，请选择日期！");
               			return;
             	   }
             	  this.loadData();
            },
            exportBtnClick:function(){
 
//            	var param="departmentType="+this.departmentType+"&projectType="+this.projectType+"&startdate="+this.reportstarttime.value+"&enddate="+this.reportendtime.value;
////				infoUtil.showLoading("正在下载...");
//				var form = this.landExportForm;
//				form.action="../client/service/landStatisticsController/exportlandStatisticsExcel?"+param;
//			    form.submit();
//			    form.remove();
//			    infoUtil.hideLoading();
 
                htmlToExcel(this.exporttabletitleinfo,this.exporttableendinfo,"landstatistic", this.currentDataList, 1);//这里的1代表的是border=1的意思。
            },
            
            //组织类型切换
            changeDepartmentTypeHandler:function(item){
            	 for(var i=0;i<this.grouplist.length;i++){
            		 dojo.toggleClass(this.grouplist[i], "itemselected", false);  
     			}
            	 var selectitem = item.currentTarget;
            	 dojo.toggleClass(selectitem, "itemselected",true);
            	 this.departmentType = selectitem.attributes["value"].value;
            	 this.ResetReportTableHeader();
            },
          //项目类型切换
            changeProjectTypeHandler:function(item){
            	
            	var selectitem = item.currentTarget;
            	this.projectType = selectitem.attributes["value"].value;
            	this.ResetReportTableHeader();
            },
            
            ResetReportTableHeader:function(){
            	var colcount = 0;
    			for(var i=0;i<this.tableheader.length;i++){
    				if(dojo.hasClass(this.tableheader[i], this.departmentType)||dojo.hasClass(this.tableheader[i], this.projectType)){  
    					//domStyle.set(this.tableheader[i],"display","block");
    					//domClass.remove(this.tableheader[i],"colshowstate");
    					dojo.toggleClass(this.tableheader[i],"colshowstate",false);
    					colcount += parseInt(this.tableheader[i].width);
    					
    					//domClass.remove(this.datatableheader[i],"colshowstate");
    					//dojo.toggleClass(this.datatableheader[i],"colshowstate",false);
    				}
    				else{
    					//domStyle.set(this.tableheader[i],"display","none");
    					dojo.toggleClass(this.tableheader[i],"colshowstate",true);
    					//dojo.toggleClass(this.datatableheader[i],"colshowstate",true);
    				}
    			}
    			 this.rightTab.setWidgetWidth(260+colcount);
    			 this.loadData();
            },
            
            /*
             * 加载数据
             */
            loadData:function(){
            	 var startdate = this.reportstarttime.value;
                 var enddate = this.reportendtime.value;
                 this.projectTypeWords = "";
                 if(this.projectType=="mocha"){
                	 this.projectTypeWords = "核查项目";
                 }
                 if(this.projectType=="qiatan"){
                	 this.projectTypeWords = "洽谈项目";
                 }
                 if(this.projectType=="huoqu"){
                	 this.projectTypeWords = "获取项目";
                 }
                	ajaxUtil.request("../client/service/landStatisticsController/queryLandList",
                			"projectType="+this.projectTypeWords+"&startdate="+startdate+"&enddate="+enddate,lang.hitch(this,function(result){
                	//this.currentDataList = dojo.clone(result.rows);
                	
                	this.createStatisticsReportData(result.rows);
            	}),function(){
                    console.error("统计数据失败");
                });
            },
            
            //构建报表数据
            createStatisticsReportData:function(source){
            		if(this.departmentType=="company"){
            			this.currentDataList = dojo.clone(this.companyList);
            			fieldnum = 1;
        			}else if(this.departmentType=="department"){
        				this.currentDataList = dojo.clone(this.departmentList);
        			}else if(this.departmentType=="teamgroup"){
        				this.currentDataList = dojo.clone(this.teamGroupList);
        				
        			}
            		  var val=Date.parse(this.reportendtime.value);
            		  var newDate1=new Date(val);
            		  
            		  var val2=Date.parse(this.reportstarttime.value);
            		  var newDate2=new Date(val2);
            		
            		for(var i=0;i<source.length;i++){
            			for(var j=0;j<this.currentDataList.length;j++){
            				if(this.departmentType=="company"&&source[i]["COMPANY"]==this.currentDataList[j]["COMPANY"]){

            					var taskTarget = 0;
            					var dateCount =null;
            	                 if(this.projectType=="mocha"){
            	                     this.projectTypeWords = "核查项目";
            	                 }
            	                 if(this.projectType=="qiatan"){
            	                     this.projectTypeWords = "洽谈项目";
            	                 }
            	                 if(this.projectType=="huoqu"){
            	                     this.projectTypeWords = "获取项目";
            	                 } 
            	                 
            					this.currentDataList[j].PNUM++;
            					this.currentDataList[j].WCD = Math.round(((this.currentDataList[j].PNUM/this.currentDataList[j].ZHIBIAO)*100)*10)/10;
            					this.currentDataList[j].LANDXHS.push(source[i]["XH"]);
            					break;
            				}
            				if(this.departmentType=="department"
            					&&source[i]["COMPANY"]==this.currentDataList[j]["COMPANY"]
            				    &&source[i]["DEPARTMENT"]==this.currentDataList[j]["DEPARTMENT"]){

            					this.currentDataList[j].PNUM++;
            					this.currentDataList[j].WCD = Math.round(((this.currentDataList[j].PNUM/this.currentDataList[j].ZHIBIAO)*100)*10)/10;
            					this.currentDataList[j].LANDXHS.push(source[i]["XH"]);
            					break;
            				}
            				if(this.departmentType=="teamgroup"
            					&&source[i]["COMPANY"]==this.currentDataList[j]["COMPANY"]
            				    &&source[i]["DEPARTMENT"]==this.currentDataList[j]["DEPARTMENT"]
            				    &&source[i]["TEAM"]==this.currentDataList[j]["TEAM"]){

            					this.currentDataList[j].PNUM++;
            					this.currentDataList[j].WCD = Math.round(((this.currentDataList[j].PNUM/this.currentDataList[j].ZHIBIAO)*100)*10)/10;
            					this.currentDataList[j].LANDXHS.push(source[i]["XH"]);
            					break;
            				}
            			}
            		}
            		this.currentDataList = listSortBy(this.currentDataList,this.sortinfo.sortfield,this.sortinfo.desc,this.sortinfo.fieldtype);
            	this._inittable(this.currentDataList);
            }, 
            /*
             * 初始化表格
             */
            _inittable:function(source){
            	var table = dojo.query("#landstatistic").empty();
            	var ths = dojo.query(".t1 th");
            	var headerstr = "<tr>";
            	var colnum = 0;
            	var colnumwidth = [];
            	for(var t=0;t<ths.length;t++){
            		var item = ths[t];
            		if(!dojo.hasClass(item, "colshowstate")){  
//            			debugger;
            			headerstr+= item.outerHTML;
            			colnum++;
            			colnumwidth.push(item.width);
            		}
            	}
            	headerstr += "</tr>";
            	
            	//通过前台导出Excel
            	this.exporttabletitleinfo = "<tr align='center'><td colspan="+colnum+" style='font-size:18px;font-weight:bold;'>土地拓展过程管控表（数据统计）</td></tr>" +
            			"<tr><td colspan=4>统计时段："+this.reportstarttime.value+"至"+this.reportendtime.value+"</td><td colspan="+(colnum-4)+">统计内容："+this.projectTypeWords+"</td></tr>"+headerstr;
            	this.exporttableendinfo = "<td align='right' colspan="+(colnum-2)+">制表日期："+formatDate(new Date())+"</td><td align='right' colspan=2>制表人："+loginusername.username+"</td>";
            	
            	//table.addContent(headerstr);
//            	var datarows = dojo.query("#landstatistic .datarow");
//            	for(var k=0;k<datarows.length;k++){
//            		var item  = datarows[k];
//            		table[0].removeChild(item);
//            	}
            	var ableExport = false;
                var html="";
                var fields = this.orgFields[this.departmentType].split(",");
                
                //进行了排序功能,根据完成度排序
                source = this.sortData(source);
                
            	for (var i=0;i<source.length;i++){
        			var item=source[i];
 
        			var tempPum = null;
        			var tempZhibiao = null; 
        			html+="<tr class='datarow' ><td style='width:"+colnumwidth[0]+"px;'>"+(i+1)+" </td>";
        			for(var j=0;j<fields.length;j++){
//        				if(j+3==fields.length){
        				if("PNUM"==fields[j].split("#")[0]){  //项目数
        					
        					var pum = item[fields[j].split("#")[0]];
        					tempPum=pum;
        					html+="<td style='width:"+colnumwidth[j+1]+"px;'><a class='projectnum' value='"+i+"'>"+(pum>0?pum:"")+"</a></td>";
        					//<img src='/sddc/client/images/export.png'></img>
        					
//        				}else if(j==fields.length-1){
        				}else if("WCD"==fields[j].split("#")[0]){ //完成度
        					var wcd = item.WCD
        					var style = wcd<100?"style='width:"+colnumwidth[j+1]+"px;color:#f00;'":"";
        					html+="<td "+style+" >"+wcd+"%</td>";
        					//debugger;
        					if(tempPum !=null && tempPum !='' && ioc.map.userInfoData.isManager){
        						html +="<td><img src='/sddc/client/images/down.jpg' value='"+i+"'></img></td>";
        						if(!ableExport){
        							ableExport = true;
        						}
        					}
        				}else{
        					//任务指标
        					if("ZHIBIAO" == fields[j].split("#")[0]){
        						var zhibiao = item[fields[j].split("#")[0]];
        						var hechaZhiBiao = item.HECHACOUNT;
        						var qiatanZhiBiao = item.QIATANCOUNT;
        					 
        						  var result='';
        						  //指标 项目类型
             	                 if(this.projectType=="mocha"){
             	                	if(hechaZhiBiao!=null && hechaZhiBiao>0){
             	                			result+=hechaZhiBiao;
             	                	}
            	                 }
            	                 if(this.projectType=="qiatan"){
              	                	if(qiatanZhiBiao!=null && qiatanZhiBiao>0){
             	                			result+=qiatanZhiBiao;
             	                	}
            	                 }
            	                 if(this.projectType=="huoqu"){
            	                     
            	                 } 
            	                 html+="<td style='width:"+colnumwidth[j+1]+"px;'>"+zhibiao+"</td>";
            	                 
        					}else{
        						html+="<td style='width:"+colnumwidth[j+1]+"px;'>"+item[fields[j].split("#")[0]]+"</td>";
        					}
        					
        				}
        			}
        		}
            	html=html.replace(/undefined/g,'');
            	table.addContent(html);
            	if(ableExport){
            		//显示导出TD
    				dojo.toggleClass(dojo.byId('exportTd'),"colshowstate",false);
            	}
            	//字母列表项点击事件
    			dojo.query(".t2 a").map(dojo.hitch(this,function(item,index){  
    				dojo.connect(item,"onclick",dojo.hitch(this,function(){  
    	            	var dataidx = item.attributes["value"].value;
    	            	var dataObj  = this.currentDataList[dataidx];
    	            	var wheresql = dataObj.LANDXHS[0];
    	            	for(var i=1;i<dataObj.LANDXHS.length;i++){
    	            		wheresql += "','"+dataObj.LANDXHS[i];
    	            	}
    	            	var params = {
    	    					url:mapinfoTemplate.LandFeatureLayer.layerurl,//"http://poc-pc:6080/arcgis/rest/services/SDDC/MyMapService/MapServer/0",
    	    					wheresql:"OBJECTID in ('"+wheresql+"')"
    	    			};
    	            	if(ioc.map.userInfoData.isManager){
        	            	this.queryListBySQL(params);
        	            	this.landareaGraphicLayer.clear();
    	            	}
    				}));  
    			}));
    			
            	//导出列表项点击事件
    			dojo.query(".t2 img").map(dojo.hitch(this,function(item,index){  
    				dojo.connect(item,"onclick",dojo.hitch(this,function(){  
    					 
    	            	var dataidx = item.attributes["value"].value;
    	            	var dataObj  = this.currentDataList[dataidx];
    	            	var wheresql = dataObj.LANDXHS[0];
    	            	for(var i=1;i<dataObj.LANDXHS.length;i++){
    	            		wheresql += "','"+dataObj.LANDXHS[i];
    	            	}
    	            	 
    	            	var param = "tableName=sddcgisdata.wytz&ids='"+wheresql+"'";
    	            	
//    	            	ajaxUtil.request("../client/service/landStatisticsController/exportWYTZInfo",
//    	            			param,lang.hitch(this,function(result){
//    	       	    			 var Store = eval(result.result);
//    	    	    			 if(Store!=null && Store.length>0){
//    	    	    				
//    	    	    				 ioc.map.userOrganization = Store;
//    	    	    			 }else{
//    	    	    				 ioc.map.userOrganization = [];
//    	    	    			 }
//    	    	    			 this.getOrganizationList();
//    	    	    			 }));
    	            	
    	            	//后台导出Excel
//    	               	
    	            	var tableName = mapinfoTemplate.LandFeatureLayer.tableName;
    	            	var condition = "tableName="+tableName+"&ids='"+wheresql+"'";
    					var form = this.wytzExportForm;
    					form.action="../client/service/landStatisticsController/exportWYTZInfo?"+condition;
    				    form.submit();
    				   // form.remove();
    				    
    				}));  
    			}));
    			
 
            },
            /*数据查询与地图展布*/
            queryListBySQL:function(params){
            	var QueryTask = new esri.tasks.QueryTask(params.url);//"http://192.168.120.69:6080/arcgis/rest/services/POC/kehu/MapServer/0");
            	var query = new esri.tasks.Query();

            	query.where = params.wheresql;//"Code = '"+attr["Code"]+"'"; 
            	query.outFields = ["*"]; 
            	query.outSpatialReference = new esri.SpatialReference(4326);//查询结果的输出投影为经纬度

            	query.returnGeometry = true; 
            	QueryTask.execute(query, dojo.hitch(this,this.queryResultHandler),function(error){
            		alert(error);
            	}); 
            },
            queryResultHandler:function(queryResult){
    			if (queryResult.features.length == 0) { 
        			return; 
        		} 
        		if (queryResult.features.length > 0) { 
        			var landlist = queryResult.features;
        			this.addLandsFeatureLayer(landlist,queryResult.fields);
        			this.map.centerAndZoom(landlist[0].geometry, 8);
        			
        		}
    		} ,
    		 addLandsFeatureLayer:function(landlist,fields){
    			for (var i = 0; i < landlist.length; i++) {
    				var land = landlist[i]; 
    				var myPolygon = {"geometry":land.geometry,
    						"attributes":land.attributes};
    				var pgra = new esri.Graphic(myPolygon);
    				pgra.fields=fields;
    				if(land.attributes.XMJD=="核查项目"){
    					pgra.setSymbol(this.POISymbols[0]);
					}else if(land.attributes.XMJD=="洽谈项目"){
						pgra.setSymbol(this.POISymbols[1]);
					}else if(land.attributes.XMJD=="获取项目"){
						pgra.setSymbol(this.POISymbols[2]);
					}
    				this.landareaGraphicLayer.add(pgra);
    			}
    		},
    		 closeDialog:function(){
     			this.inherited("closeDialog",arguments);
     			this.rightTab.expandBtn.click();
     			this.landareaGraphicLayer.clear();
     			this.destroy();
     		},
            destroy: function () {
                var widgets = this.widgets;
                for (var name in widgets) {
                    if (widgets[name]) {
                        widgets[name].destroy();
                    }
                }
                this.inherited(arguments);
            },
            changeSortFieldHandler:function(){
            	if(this.sortinfo.sortfield=="WCD"){
            		this.sortinfo.sortfield = "COMPANY";
            		this.sortinfo.fieldtext = "城市";
            		this.sortinfo.fieldtype = "ChineseText";
            		this.sortinfo.desc = "asc";
            	}else{
            		this.sortinfo.sortfield="WCD";
            		this.sortinfo.fieldtext = "完成度";
            		this.sortinfo.fieldtype = "Number";
            		this.sortinfo.desc = "desc";
            	}
            	
            	dojo.byId("sortfieldtext").innerText = this.sortinfo.fieldtext;
            	this.currentDataList = listSortBy(this.currentDataList,this.sortinfo.sortfield,this.sortinfo.desc,this.sortinfo.fieldtype);
            	this._inittable(this.currentDataList);
            },
            
            
            //项目数跟指标数都会与时间成比例(一个月) ,计算后返回最终的根据完成度排序后的数组
            sortData:function(source){
                var resaultArray = new Array();
            	for (var i=0;i<source.length;i++){
        			var item=source[i];
        			var tempPum = null;
        			var tempZhibiao = null; 
        			var fields = this.orgFields[this.departmentType].split(",");
        			for(var j=0;j<fields.length;j++){
//        				if(j+3==fields.length){
        				if("PNUM"==fields[j].split("#")[0]){  //项目数
        					
        					var pum = item[fields[j].split("#")[0]];
        					tempPum=pum;
        					 
//        				}else if(j==fields.length-1){
        				}else if("WCD"==fields[j].split("#")[0]){ //完成度
//        					var wcd = item[fields[j].split("#")[0]];
        					var wcd = 0;
        					if(tempZhibiao!=null && tempZhibiao>0){
        						wcd=Math.round(((tempPum>0?pum:0)/tempZhibiao)*100)
        					}
        					item.WCD = wcd;
  
        				}else{
        					//任务指标
        					if("ZHIBIAO" == fields[j].split("#")[0]){
        						var zhibiao = item[fields[j].split("#")[0]];
        						var hechaZhiBiao = item.HECHACOUNT;
        						var qiatanZhiBiao = item.QIATANCOUNT;
        						var year = this.reportendtime.value.split('-')[0];
        						var month = this.reportendtime.value.split('-')[1];
        						var val2=Date.parse(this.reportendtime.value.replace(/'-'/g,''));
        						var val=Date.parse(this.reportstarttime.value.replace(/'-'/g,''));
        						  var newDate=new Date(val2)-new Date(val);
        						  
        						  //指标与日期成比例
        						  var t = newDate/1000/3600/24 ; //开始结束时间差
        						  var t1 = new Date(year,month,'0').getDate();//当前月的天数
        						  var per  =  (t+1)/t1;
        						  var result=0;
        						  //指标 项目类型
             	                 if(this.projectType=="mocha"){
//             	                	zhibiao = zhibiao*10;
             	                	 
             	                	if(hechaZhiBiao!=null && hechaZhiBiao>0){
             	                			result+=Math.round(((Math.round(per*10)/10)*hechaZhiBiao));
//             	                			result+=hechaZhiBiao;
             	                	}
            	                 }
            	                 if(this.projectType=="qiatan"){
//            	                	 zhibiao =  zhibiao*4;
              	                	if(qiatanZhiBiao!=null && qiatanZhiBiao>0){
             	                			result+=Math.round(((Math.round(per*10)/10)*qiatanZhiBiao));
//             	                			result+=qiatanZhiBiao;
             	                	}
            	                 }
            	                 if(this.projectType=="huoqu"){
            	                     
            	                 } 
            	                 
            	                 tempZhibiao = result; //最终的指标数量
            	                 item.ZHIBIAO = tempZhibiao;
        					} 
        					
        				}
        			}
        			resaultArray.push(item);
        		}
            	 
            	this.currentDataList = listSortBy(resaultArray,this.sortinfo.sortfield,this.sortinfo.desc,this.sortinfo.fieldtype);
            	return this.currentDataList;
            }
        });
    });